package com.demboos.galaxy.music.widget;

import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;

public class WidgetConfigActivity extends Activity {

	int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;

	RadioButton mRadioOriginalLayout;
	RadioButton mRadioWithPrevLayout;
	RadioButton mRadioSolid;
	RadioButton mRadioSemi;
	RadioButton mRadioTransparent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.config_activity);

		// Set the result to CANCELED. This will cause the widget host to cancel
		// out of the widget placement if they press the back button.
		setResult(RESULT_CANCELED);

		Intent intent = getIntent();
		Bundle extras = intent.getExtras();
		if (extras != null) {
			mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
					AppWidgetManager.INVALID_APPWIDGET_ID);
		}

		mRadioOriginalLayout = (RadioButton) findViewById(R.id.RadioButtonLayoutOriginal);
		mRadioWithPrevLayout = (RadioButton) findViewById(R.id.RadioButtonLayoutWithPrev);
		
		
		mRadioSolid = (RadioButton) findViewById(R.id.RadioButtonSolid);
		mRadioSemi = (RadioButton) findViewById(R.id.RadioButtonSemiTransparent);
		mRadioTransparent = (RadioButton) findViewById(R.id.RadioButtonTransparent);

		mRadioOriginalLayout.setChecked(true);
		mRadioSolid.setChecked(true);

		findViewById(R.id.ButtonSave).setOnClickListener(mOnClickListener);

		if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
			finish();
		}
	}

	View.OnClickListener mOnClickListener = new View.OnClickListener() {
		public void onClick(View v) {
			if (mRadioOriginalLayout.isChecked()) {
				if (mRadioSolid.isChecked()) {
					WidgetConfigDatabase.setLayoutKey(v.getContext(), mAppWidgetId,
							R.layout.eclair_album_appwidget);
				} else if (mRadioSemi.isChecked()) {
					WidgetConfigDatabase.setLayoutKey(v.getContext(), mAppWidgetId,
							R.layout.eclair_album_appwidget_semitransparent);
				} else if (mRadioTransparent.isChecked()) {
					WidgetConfigDatabase.setLayoutKey(v.getContext(), mAppWidgetId,
							R.layout.eclair_album_appwidget_transparent);
				}
				
			} else if (mRadioWithPrevLayout.isChecked()) {
				if (mRadioSolid.isChecked()) {
					WidgetConfigDatabase.setLayoutKey(v.getContext(), mAppWidgetId,
							R.layout.eclair_album_appwidget_with_prev);
				} else if (mRadioSemi.isChecked()) {
					WidgetConfigDatabase.setLayoutKey(v.getContext(), mAppWidgetId,
							R.layout.eclair_album_appwidget_with_prev_semitransparent);
				} else if (mRadioTransparent.isChecked()) {
					WidgetConfigDatabase.setLayoutKey(v.getContext(), mAppWidgetId,
							R.layout.eclair_album_appwidget_with_prev_transparent);
				}
				
			}

			GalaxyMediaAppWidgetProvider.defaultAppWidget(v.getContext(),
					new int[] { mAppWidgetId });

			Intent resultValue = new Intent();
			resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
					mAppWidgetId);
			setResult(RESULT_OK, resultValue);
			finish();
		}
	};
}
